
OPTIONS COMPRESS = YES OBS = MAX;

libname inter "D:\Data\inter";

*Create age profiles by group;
%macro b_group(group);
proc means data = inter.rep_alcohol noprint;
   var  TOTCHG;
   output out = &group. (rename = (_FREQ_ = counts_&group.)) mean = charges_&group.;
   class months_21;
   where state in ('AZ','NJ','WI') and preg_related = 0 and &group. = 1;
run;
%mend;

%b_group(visit);*Whole sample;
%b_group(illness);*Ilness;
%b_group(injury_or_alc);
%b_group(alcohol_any);
%b_group(inj_accident);
%b_group(inj_by_self);
%b_group(inj_by_oth);

*Combine these;
data combined;
   merge visit illness injury_or_alc alcohol_any inj_accident inj_by_self inj_by_oth;
   by months_21;
   if months_21 = . then delete;
run;

*Dataset for Stata;
proc export data=combined outfile= "C:\Research\Alcohol and Morbidity\7. Code Archive\Data Files and Code That Produced Them\P10 Check Profiles of Charges in ED data by Cause.dta" replace;
run;

